#include "vzbase/base/loggingsettings.h"
#include "vzbase/flags/vzflags.h"
#include <stdlib.h>

namespace vzbase {

void PrintUsage() {
  printf("\n");
  printf("\n");
  printf("  usage:\n");
  printf("\n");
  printf(
    "        -e  <logtostderr>     Defualt value is 0 (google::GLOG_INFO)\n");
  printf(
    "        -m  <miniloglevel>    Default value is 2 (google::GLOG_ERROR)\n");
  printf(
    "        -v                    Verbose Mode\n");
  printf("\n");
  printf(
    "       [-h]                   print usage\n");
  printf("\n");
}

void InitLoggingSystem(int argc, char *argv[]) {

#ifdef USE_GLOG
  google::InitGoogleLogging(argv[0]);
  FLAGS_logtostderr = true;
#ifdef WIN32
  FLAGS_stderrthreshold = google::GLOG_ERROR;
  FLAGS_minloglevel     = google::GLOG_INFO;
#else
  FLAGS_stderrthreshold = google::GLOG_INFO;
  FLAGS_minloglevel     = google::GLOG_ERROR;
#endif
  FLAGS_colorlogtostderr = true;

  int opt = 0;
  while((opt = getopt(argc, argv, "e:m:o:vh")) != -1) {
    switch (opt) {
    case 'e':
      FLAGS_stderrthreshold = atoi(optarg);
      LOG(INFO) << "FLAGS_stderrthreshold = " << FLAGS_stderrthreshold;
      break;
    case 'm':
      FLAGS_minloglevel     = atoi(optarg);
      LOG(INFO) << "FLAGS_minloglevel = " << FLAGS_minloglevel;
      break;
    case 'v':
      FLAGS_stderrthreshold = google::GLOG_ERROR;
      FLAGS_minloglevel     = google::GLOG_INFO;
      LOG(INFO) << "FLAGS_stderrthreshold = google::GLOG_ERROR";
      LOG(INFO) << "FLAGS_minloglevel     = google::GLOG_INFO";
      break;
    case 'o':
      LOG(INFO) << "FLAGS_logtostderr     = false;";
      LOG(INFO) << "FLAGS_stderrthreshold = google::GLOG_INFO";
      LOG(INFO) << "FLAGS_log_dir         = " << optarg;
      LOG(INFO) << "FLAGS_max_log_size    = 10";
      FLAGS_logtostderr     = false;
      FLAGS_stderrthreshold = google::GLOG_INFO;
      FLAGS_log_dir         = optarg;
      FLAGS_max_log_size    = 10;
      break;
    case 'h':
      PrintUsage();
      break;
    }
  }
#endif
  return ;
}

}  // namespace vzbase

